package top.maof.book.spider.develop;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import top.maof.book.model.Contents;
import top.maof.book.service.BookService;
import top.maof.book.service.ContentsService;
import top.maof.book.utils.SpringContext;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.PageModelPipeline;

/**
 * 保存书信息
 */
@Component
@Slf4j
public class BookPageModelPipeline implements PageModelPipeline<Split> {
    @Autowired
    BookService bookService;

    @Override
    public void process(Split split, Task task) {
        if (split.getBook() != null) {
            int i = 0;
            try {
                i = bookService.add(split.getBook());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (i > 0)
                log.info(split.getBook().toString());
        }
    }
}
